$(function() {
	$(".cell-item").click(function() {
		$(this).find("input").focus()
	})
	$("#cx").click(function() {
		$('#J_List').unbind()
		abb()
	})
	$("#J_List").delegate('.img','click',function(){
		YDUI.dialog.loading.open('准备拨打电话')
		var tel=$(this).attr("tel")
		var hd_code=$(this).parents("li").attr("hd_code")
		var userTel = Base64.encode(tel)
		$.post("userCall",{activityType:hd_type,activityNumber:hd_code,userTel:userTel},function(data){
			/*alert(JSON.stringify(data))*/
			YDUI.dialog.loading.close()
			if(data.code==0){
				abb()
				window.location.href="tel:"+tel
			}else{
				alert(data.message)
			}
		})
	})
	var hd_type = sessionStorage.getItem("code")
	abb()

	function abb() {
		
		$('#J_ListContent').html("")
		$(".list-donetip").css("display", "none")
		var page = 1;
		var pageSize = 5;
		var name = $("#userName").val()
		var type = $(".type").val()
		var hfkh=$(".hfkh").val()
		$('#J_List').infiniteScroll({
			binder: $("#J_List"),
			pageSize: pageSize,
			initLoad: true,
			loadingHtml: '<strong>加载中...</strong>',
			loadListFn: function() {
				var def = $.Deferred();
				$.ajax({
					url: 'selectActivityListByUserDept',
					dataType: 'json',
					type: 'POST',
					data: {
						page: page,
						rows: pageSize,
						name: name,
						activityType: hd_type,
						number5: type,
						callNumber:hfkh
					},
					success: function(res) {
						if(res.code == 0) {
						/*	alert(page,pageSize)*/
							var num = res.data.total
							var rel = res.data.rows
							$(".num").val(num)
							var html = ''
							for(var i = 0; i < rel.length; i++) {
								html += '<li hd_code="'+rel[i].活动号+'"><h3>姓名：' + hb_null(rel[i].姓名) + '<span>' + hb_null(rel[i].手机号) + '</span></h3>';
								html += '<p>回访次数：' + hb_null(rel[i].回访次数) + '</p>'
								html += '<p>抽奖时间：' + rel[i].登记时间 + '</p>'
								html += '<p style="height:auto">奖品：' + add(rel[i].奖品列表)+'</p>';
								html += '<img src="img/tel.png" class="img" tel="'+hb_null(rel[i].手机号) + '"></li>'
							}
							$('#J_ListContent').append(html);
							if(rel.length == 0) {
								def.resolve(['']);
							} else {
								def.resolve(rel);
							}
							++page
						} else {
							def.resolve(['']);
							alert(res.msg)
						}
					}
				});
				return def.promise();
			}
		});
	}

	function add(row) {
		var html=''
		
		for(var i in row){
			if(row[i].备注=='1'){
				
				html+='<span class="badge badge-radius badge-primary">'+row[i].奖品名称+'(已兑换)'+'</span>'
			}else{
				
				html+='<span class="badge badge-radius badge-danger">'+row[i].奖品名称+'(未兑换)'+'</span>'
			}
		}
		return html
	}
})